<template>
  <Dialog :title="t('student.interviewList.title')" v-model="dialogVisible" width="100%">
    <ContentWrap>
      <!-- 搜索工作栏 -->
      <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">
        <el-form-item :label="t('student.fields.studentName')" prop="studentName">
          <el-input
            v-model="queryParams.studentName"
            :placeholder="t('common.inputTextPlaceholder') + t('student.fields.studentName')"
            clearable
            @keyup.enter="handleQuery"
            class="!w-160px"
          />
        </el-form-item>
        <el-form-item :label="t('student.fields.phone')" prop="phone">
          <el-input
            v-model="queryParams.phone"
            :placeholder="t('common.inputTextPlaceholder') + t('student.fields.phone')"
            clearable
            @keyup.enter="handleQuery"
            class="!w-160px"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="handleQuery">
            <Icon icon="ep:search" class="mr-5px" />
            {{ t('common.search') }}
          </el-button>
          <el-button @click="resetQuery">
            <Icon icon="ep:refresh" class="mr-5px" />
            {{ t('common.reset') }}
          </el-button>
        </el-form-item>
      </el-form>
    </ContentWrap>

    <!-- 列表 -->
    <ContentWrap>
      <vxe-table
        v-loading="loading"
        :data="list"
        stripe
        :row-config="{ keyField: 'id' }"
        :column-config="{ resizable: true }"
        :size="vxeTableSize"
      >
        <vxe-column type="seq" width="50" align="center" fixed="left" />
        <vxe-column
          :title="t('student.fields.studentName')"
          field="studentName"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
          fixed="left"
        />
        <vxe-column
          :title="t('student.fields.phone')"
          field="phone"
          align="center"
          show-header-overflow
          show-overflow
          min-width="120"
        />
        <vxe-column
          :title="t('student.fields.university')"
          field="university"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('student.fields.studyMajor')"
          field="studyMajor"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('student.fields.attachment')"
          field="attachment"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        >
          <template #default="scope">
            <FileObjectDownload :file-json="scope.row.attachment" />
          </template>
        </vxe-column>
        <vxe-column
          :title="t('student.fields.interviewScore')"
          field="interviewScore"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('student.fields.interviewTime')"
          field="interviewTime"
          align="center"
          show-header-overflow
          show-overflow
          min-width="120"
        />
        <vxe-column
          :title="t('student.fields.interviewSlotTime')"
          field="interviewSlotTime"
          align="center"
          show-header-overflow
          show-overflow
          min-width="140"
        />
        <vxe-column
          :title="t('student.fields.interviewGroupId')"
          field="groupName"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('student.fields.interviewStatus')"
          field="interviewStatus"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
      </vxe-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>

<script setup lang="ts">
import { RecruitStudentGroupingListRespVO, StudentApi } from '@/api/recruit/recruitstudent'
import type { VxeTablePropTypes } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'
import { InterviewGroupSpecialListRespVO } from '@/api/recruit/interviewgroup'
import FileObjectDownload from '@/components/FileObjectDownload/index.vue'

/** 指定面试下的学生列表 */
defineOptions({ name: 'RecruitStudentListInInterviewForSpecialist' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<RecruitStudentGroupingListRespVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const dialogVisible = ref(false)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  studentName: undefined,
  phone: undefined,
  batchId: undefined,
  interviewId: undefined
})
const queryFormRef = ref() // 搜索的表单

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await StudentApi.getStudentGroupingList(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  queryParams.batchId = currentInterview.value?.batchId as any
  queryParams.interviewId = currentInterview.value?.interviewId as any
  handleQuery()
}

const currentInterview = ref<InterviewGroupSpecialListRespVO>()

// 面试管理-设置分组 新增第一步 弹出学生列表
const open = async (interview: InterviewGroupSpecialListRespVO) => {
  currentInterview.value = interview
  dialogVisible.value = true
  await nextTick()
  resetQuery()
}

defineExpose({
  open
})
</script>

<style lang="scss" scoped>
:deep(.vxe-cell--checkbox.is--disabled) {
  .vxe-table-icon-checkbox-unchecked:before {
    content: '\e67d';
  }
}

:deep(.el-form--inline .el-form-item) {
  margin-right: 10px !important;
}

:deep(.vxe-cell .el-button + .el-button) {
  margin-left: 0;
}
</style>
